package com.xs.tool.common.hanlp;

import com.hankcs.hanlp.HanLP;

import java.util.List;

/**
 * 自然语言处理工具
 * @author xs
 * @date 2020
 */
public class HanlpUtil {
    public static List<String> extractSummary(String document){
        return extractSummary(document,5);
    }
    /**
     * 自动摘要
     * @return
     */
    public static List<String> extractSummary(String document,int size){
        if(null == document || document.equals("")){
            return null;
        }
        size = size<=0?3:size;
        try {
            List<String> sentenceList = HanLP.extractSummary(document, size);
            return sentenceList;
        }catch (Exception e){
            e.printStackTrace();
        }
        return null;
    }
    public static List<String> extractKeyword(String document){
        return extractKeyword(document,10);
    }
    /**
     * 关键词提取
     * @return
     */
    public static List<String> extractKeyword(String document,int size){
        if(null == document || document.equals("")){
            return null;
        }
        size = size<=0?3:size;
        try {
            List<String> keywordList = HanLP.extractKeyword(document, 5);
            return keywordList;
        }catch (Exception e){
            e.printStackTrace();
        }
        return null;
    }
}
